Skip to content

refactor(agent): decompose entrypoint.py into modular src/ package wi…#23

Merged
krokoko merged 5 commits intomainfrom
agent-refactoring
Apr 12, 2026
Merged

refactor(agent): decompose entrypoint.py into modular src/ package wi…#23
krokoko merged 5 commits intomainfrom
agent-refactoring

Conversation

@krokoko
Copy link
Copy Markdown
Contributor

@krokoko krokoko commented Apr 12, 2026

…th Cedar policy engine

Fixes #20, #18, #19

Decompose the monolithic agent/entrypoint.py (~2,100 lines) into 13 focused modules under agent/src/, add a Cedar-based policy engine for tool-call governance, and fix 15 review findings across Python and CDK TypeScript code.

Agent decomposition:

  • config.py, models.py (TaskType enum), pipeline.py, runner.py, context.py, prompt_builder.py, hooks.py, policy.py, post_hooks.py, repo.py, shell.py, telemetry.py
  • entrypoint.py retained as re-export shim for backward compatibility

Cedar policy engine (agent/src/policy.py + hooks.py):

  • In-process cedarpy evaluation with deny-list model (fail-closed)
  • pr_review agents denied Write/Edit; protected path and destructive command blocking for all agents
  • Per-repo custom Cedar policies via Blueprint security.cedarPolicies
  • PreToolUse hook integration with Claude Agent SDK
  • POLICY_DECISION telemetry events on denied decisions

CDK changes:

  • Blueprint cedarPolicies resolved to readonly property
  • context-hydration: POLICY_EXTRACTORS mapping table, managedWordLists support, formatGuardrailBlocked helper, tightened filter_type union
  • cedar_policies passthrough in orchestrator and repo-config

Tests: 139 Python (6 new test files), 604 CDK (4 files updated)
Documentation: 7 docs updated for new module structure and Cedar status

Area

  • cdk — infrastructure, handlers, constructs
  • agent — Python runtime / Docker image
  • clibgagent client
  • docs — guides or design sources (docs/guides/, docs/design/)
  • tooling — root mise.toml, scripts, CI workflows

Tip: AGENTS.md lists where to edit and which tests to extend.

Related

Changes

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.

bgagent added 2 commits April 12, 2026 13:10
…th Cedar policy engine

Decompose the monolithic agent/entrypoint.py (~2,100 lines) into 13
focused modules under agent/src/, add a Cedar-based policy engine for
tool-call governance, and fix 15 review findings across Python and CDK
TypeScript code.

Agent decomposition:
- config.py, models.py (TaskType enum), pipeline.py, runner.py,
  context.py, prompt_builder.py, hooks.py, policy.py, post_hooks.py,
  repo.py, shell.py, telemetry.py
- entrypoint.py retained as re-export shim for backward compatibility

Cedar policy engine (agent/src/policy.py + hooks.py):
- In-process cedarpy evaluation with deny-list model (fail-closed)
- pr_review agents denied Write/Edit; protected path and destructive
  command blocking for all agents
- Per-repo custom Cedar policies via Blueprint security.cedarPolicies
- PreToolUse hook integration with Claude Agent SDK
- POLICY_DECISION telemetry events on denied decisions

Critical fixes:
- log() was silently discarding message text
- PolicyEngine changed from fail-open to fail-closed
- Hook fallbacks now deny (not silently allow) on invalid inputs

CDK changes:
- Blueprint cedarPolicies resolved to readonly property
- context-hydration: POLICY_EXTRACTORS mapping table, managedWordLists
  support, formatGuardrailBlocked helper, tightened filter_type union
- cedar_policies passthrough in orchestrator and repo-config

Tests: 139 Python (6 new test files), 604 CDK (4 files updated)
Documentation: 7 docs updated for new module structure and Cedar status
Cedar entity UIDs use Type::"id" format — when the resource ID
contained double quotes (e.g. git commit -m "fix bug"), the parser
failed and returned NoDecision, which fail-closed denied the call.
This blocked virtually all real git/gh commands in production.

Fix: use fixed sentinel resource IDs ("command" for execute_bash,
"file" for write_file) instead of embedding raw command/path text
in the Cedar entity UID. The deny-list policies only match on
context.command and context.file_path, never on the resource ID,
so behavior is identical.
Comment thread agent/src/shell.py Fixed
bgagent added 2 commits April 12, 2026 13:46
…ng, doc notes

- Add Cedar deny pattern for bare `git push -f` (no trailing args)
- Track UserMessage in message_counts, log string content
- Extract _format_tool_result helper to deduplicate ToolResultBlock formatting
- Parametrize quote-handling tests
- Document sentinel resource ID constraint for custom Cedar policies
  in policy.py module docstring and SECURITY.md
@krokoko krokoko marked this pull request as ready for review April 12, 2026 19:30
@krokoko krokoko requested a review from a team as a code owner April 12, 2026 19:30
@krokoko krokoko merged commit d5d6cf5 into main Apr 12, 2026
5 of 6 checks passed
@krokoko krokoko deleted the agent-refactoring branch April 12, 2026 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Orchestrator: Improve guardrail error experience for blocked tasks

2 participants